import { Component, EventEmitter, HostBinding, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';

@Component({
  selector: 'bz-view-tips',
  templateUrl: './view-tips.component.html',
  styles: []
})
export class ViewTipsComponent implements OnInit, OnChanges {

  /** 显示关闭状态是否由用户接管 */
  @Input() isControl = false;
  /** 是否显示tips */
  @Input() isShow = true;
  @HostBinding('class.show') show = true;
  @Output() isShowChange = new EventEmitter();
  /** 是否显示关闭按钮 */
  @Input() isShowClose = true;
  /** 关闭时的回调，状态由用户完全控制时不自动关闭 */
  @Output() close = new EventEmitter();

  ngOnInit() {
  }

  ngOnChanges(changes: SimpleChanges): void {
    if (changes.isShow) {
      this.show = changes.isShow.currentValue;
    }
  }

  onClose() {
    if (!this.isControl) {
      this.show = false;
      this.isShowChange.emit(false);
    }
    this.close.emit();
  }
}
